package com.atguigu.servlet;

import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.FileReader;
import java.io.IOException;

public class Servlet06ServletContext extends HttpServlet {

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ServletContext servletContext = getServletContext();

        String virtualPath = "/WEB-INF/web.xml";

        String realPath = servletContext.getRealPath(virtualPath);

        FileReader fileReader = new FileReader(realPath);

        char[] buffer = new char[1024];

        int len = -1;

        while ((len = fileReader.read(buffer)) != -1) {
            response.getWriter().write(buffer, 0, len);
        }
    }
}
